package org.lql.algo.codecrush.hot100.hash;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: liangqinglong
 * @date: 2025-09-16 20:50
 * @description: 两数之和 <a href="https://leetcode.cn/problems/two-sum/?envType=study-plan-v2&envId=top-100-liked">...</a>
 **/
public class TwoSum {

	public int[] twoSum(int[] nums, int target) {
		Map<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i < nums.length; i++) {
			if (map.containsKey(target - nums[i])) {
				return new int[]{map.get(target - nums[i]), i};
			}
			map.put(nums[i], i);
		}
		return new int[]{};
	}

	public static void main(String[] args) {
		TwoSum twoSum = new TwoSum();
		int[] nums = new int[]{2, 7, 11, 15};
		System.out.println(Arrays.toString(twoSum.twoSum(nums, 9)));
	}
}
